﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolERP_BLL;
using CoolERP_Entities;

namespace CoolERP_Web.User
{
    public partial class XSHTMX : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindData();
        }

        private void BindData()
        {
            int RecordCount = 0;
            vXSHT entity = new vXSHT();
            using (XSHTBLL xBLL = new XSHTBLL())
            {
                Dictionary<string, string> dc = new Dictionary<string, string>();
                dc.Add("ID", this.GetUrlParam("id").ToString());
                entity = xBLL.GetXSHT(dc, "BH", null, 1, out RecordCount).FirstOrDefault();
                if (entity != null)
                {
                    liBH.Text = entity.BH;
                    liKHMC.Text = entity.KHJC;
                    liKHLXR.Text = entity.LXR;
                    liLXFS.Text = entity.LXRSJ;
                    liDepartment.Text = entity.BMMC;
                    liSaler.Text = entity.RYMC;
                    liCHFS.Text = entity.CHFS;
                    liDHSJ.Text = entity.DHSJ.Value.ToString("yyyy-MM-dd HH:mm");
                    liCHSJ.Text = entity.CHSJ.Value.ToString("yyyy-MM-dd HH:mm");
                    liZT.Text = entity.HTZT != null && Convert.ToInt32(entity.HTZT) == 1 ? "已完成" : "未完成";
                    
                }
            }
            //明细表
            using (XSHTMXBBLL xBLL = new XSHTMXBBLL())
            {
                List<XSHTMXBModel> mxbs = xBLL.GetXSHTMXB(t => t.XSHTID == entity.ID, "", null, 1, out RecordCount);
                GridView1.DataSource = mxbs;
                GridView1.DataBind();
                liMoney.Text = mxbs.Sum(t => t.SL * t.DJ).Value.ToString("C");
            }
        }
    }
}